$(document).ready(function () {
    //登录
    $("#login").click(function(){
        //终端设备
        var browser = {
            versions: function () {
                var u = navigator.userAgent, app = navigator.appVersion;
                return { //移动终端浏览器版本信息
                    ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                    android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
                    iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                    iPad: u.indexOf('iPad') > -1, //是否iPad
                };
            }(),
        }
        var user_name=$('#user_name').val();
        var user_pw=$('#user_pw').val();
        if (browser.versions.iPhone || browser.versions.iPad || browser.versions.ios) {
            var platform='IOS';
        }
        if (browser.versions.android) {
            var platform='android';
        }
        var version='1.0';
        var platform_name='ce';
        var login_url=myconfig['api']+'login';
        $.post(login_url, {version:version,username:user_name,platform_name:platform_name,platform:platform,password:user_pw},function(data,status){
            if(data.data.length == 0){
                art.dialog({
                    lock: true,
                    fixed: true,
                    icon: 'face-sad',
                    title: '错误提示',
                    content: data.msg,
                    ok: true
                });
                return false;
            }
            sessionStorage.setItem("random", data.data.random);
            sessionStorage.setItem("userid", data.data.userid);
            sessionStorage.setItem("nickname", data.data.nickname);
            var user_list=myconfig['api']+'get_userinfo&random='+data.data.random+'&userid='+data.data.userid+'';
            $.get(user_list, {},function(datas,sta){
                sessionStorage.setItem("nickname", datas.nickname);
                sessionStorage.setItem("groupid", datas.groupid);
                sessionStorage.setItem("avatar", datas.avatar);
                sessionStorage.setItem("phone", datas.phone);
                sessionStorage.setItem("email", datas.email);
                sessionStorage.setItem("money", datas.money);
                sessionStorage.setItem("point", datas.point);
                sessionStorage.setItem("group_name", datas.group_name);
                sessionStorage.setItem("phone_status", datas.phone_status);
                sessionStorage.setItem("email_status", datas.email_status);
                sessionStorage.setItem("alipay_status", datas.alipay_status);
                sessionStorage.setItem("name", datas.name);
                sessionStorage.setItem("bank_status", datas.bank_status);
                sessionStorage.setItem("qq", datas.qq);
                sessionStorage.setItem("name_status", datas.name_status);
                if(data.status==1){
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-smile',
                        title: '提示',
                        content: data.msg,
                        okVal: '确定',
                        ok:function() {
                            window.location.href='../tab_user.html';
                        }
                    });
                }else{
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-sad',
                        title: '错误提示',
                        content: data.msg,
                        ok: true
                    });
                }
            },'json');

        },'json');
    });
});